#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const int maxn = 1e8 + 100;
bool dp[maxn];

void init(int n) {
    for (int i = 0; i <= n; i++)dp[i] = true;
    dp[0] = dp[1] = false;
    for (int i = 2; i <= n / i; i++) {
        if (dp[i]) {
            for (int j = 2 * i; j <= n; j += i) {
                dp[j] = false;
            }
        }
    }
}

ll r1(ll n) {
    ll m = n / 10;
    while (n > 0) {
        m = m * 10 + n % 10;
        n /= 10;
    }
    return m;
}

ll r2(ll n) {
    ll m = n;
    while (n > 0) {
        m = m * 10 + n % 10;
        n /= 10;
    }
    return m;
}


int main() {

    ll a, b;

    while (cin >> a >> b) {
        init(b);
        vector<ll> v;
        for (ll i = 1; i <= b; i++) {
            ll j = r1(i);
            ll k = r2(i);
            if (j >= a && j <= b && dp[j]) {
                v.push_back(j);
            }
            if (k >= a && k <= b && dp[k]) {
                v.push_back(k);
            }
            if (j >= b)break;

        }
        sort(v.begin(), v.end());
        for (auto e:v) {
            cout << e << endl;
        }
        cout << endl;
    }

    return 0;
}